/**
 * 
 */
package org.tiger.springboot.redis.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.tiger.common.domain.ResponseBean;
import org.tiger.springboot.redis.service.IRedisTemplateService;

/**
 * @author liuwenlai
 *
 */
@Service
public class RedisTemplateServiceImpl implements IRedisTemplateService {
	
	private Logger logger = LoggerFactory.getLogger(RedisTemplateServiceImpl.class);

	@Autowired
	private StringRedisTemplate redisTemplate;

	@Override
	public ResponseBean<Object> getObjByKey(String key) {
		ResponseBean<Object> bean = new ResponseBean<Object>();
		String value = redisTemplate.opsForValue().get(key);
		bean.setResult(value);
		return bean;
	}

	@Override
	public boolean hasKey(String key) {
		boolean hasKey = redisTemplate.hasKey(key);
		return hasKey;
	}

	@Override
	public boolean deleteKey(String key) {
		return redisTemplate.delete(key);
	}

	@Override
	public void setObj(String key, Object value) {
		logger.info("key:"+key+";value:"+value);
		redisTemplate.opsForValue().set(key, String.valueOf(value).toString());
		// redisTemplate.opsForValue().set(arg0, arg1, arg2);
	}

}
